package com.holyant.goods.enums;

public enum OperateTypeEnum {


    /**
     * 其它
     */
    OTHER(0, "其它"),
    /**
     * 新增
     */
    INSERT(1, "新增"),
    /**
     * 修改
     */
    UPDATE(2, "修改"),
    /**
     * 删除
     */
    DELETE(3, "删除"),
    /**
     * 启用
     */
    ENABLE(12, "启用"),
    /**
     * 停用
     */
    DISABLE(13, "停用");

    private final Integer code;
    private final String name;

    OperateTypeEnum(Integer code, String name)
    {
        this.code = code;
        this.name = name;
    }

    public static OperateTypeEnum ofCode(Integer code) {
        for (OperateTypeEnum value : values()) {
            if (value.code.compareTo(code) == 0) return value;
        }
        throw new RuntimeException("unknown GdsBusinessCategory status code");
    }

    public Integer getCode()
    {
        return code;
    }

    public String getName()
    {
        return name;
    }

    public static String getNameByCode(Integer code) {
        for (OperateTypeEnum item : OperateTypeEnum.values()) {
            if (item.getCode().equals(code)) {
                return item.getName();
            }
        }
        return null;
    }

    public static Integer getCodeByName(String name) {
        for (OperateTypeEnum item : OperateTypeEnum.values()) {
            if (item.getName().equals(name)) {
                return item.code;
            }
        }
        return null;
    }

    public static OperateTypeEnum parse(Integer code) {
        for (OperateTypeEnum item : OperateTypeEnum.values()) {
            if (item.getCode().equals(code)) {
                return item;
            }
        }
        return null;
    }

    public static OperateTypeEnum parseByName(String name) {
        for (OperateTypeEnum item : OperateTypeEnum.values()) {
            if (item.getName().equals(name)) {
                return item;
            }
        }
        return null;
    }

    public boolean atStatus(Integer code){
        return this.code.compareTo(code) == 0;
    }
}
